Repository navigation
fs: resolve glob exclude Dirent paths against cwd option - #67268
yohannesjoya wants to merge 1 commit into
Conversation
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
|
@lpinca could you take a look at this one? It's a small fix for |
|
Friendly ping: this has an approval from @jasnell but no CI run yet. Could a collaborator add |
|
CI run 79529 failed only on |
|
the test failure is relevant:
|
When withFileTypes is true, an exclude function receives a Dirent. For a path that a glob pattern reaches directly, that Dirent was built by calling lstat on a path relative to the cwd option, but lstat resolved it against the process working directory. The function could then see the type and parent path of an unrelated file, or see nothing at all if no such file existed. Resolve the path against the cwd option before calling lstat. Refs: nodejs#63535 Co-authored-by: Minh Vu <vuhoangminh97@gmail.com> Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com>
d33378d to
80c60b2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67268 +/- ##
==========================================
- Coverage 92.99% 90.51% -2.49%
==========================================
Files 428 805 +377
Lines 195633 285881 +90248
Branches 30281 55197 +24916
==========================================
+ Hits 181937 258758 +76821
- Misses 13369 17212 +3843
- Partials 327 9911 +9584
🚀 New features to boost your workflow:
|
|
Thanks, fixed. The test calls |
When
withFileTypesis true, anexcludefunction receives aDirent. For a path that a pattern reaches directly, such asaina/**, the walker passes a path relative tooptions.cwd. The shim then calledlstatSync()on it, and that resolved againstprocess.cwd().So the callback saw the wrong entry when the same name exists in the process working directory. In the test below,
ais a directory incwdand a file in the process working directory, andexclude: (d) => d.isDirectory()failed to exclude it. If no such name exists,lstatSync()throws, and the callback is skipped for that path.This change resolves the path against
options.cwdbefore callinglstatSync(), the same way#toDirent()does. Absolute paths are unchanged, and so is the defaultcwd.fallintoplace reported this in #63535 and sent #63538. Both were closed as stale without a review. #63538 targeted the JavaScript glob implementation that was later replaced by the native one, so this is a new patch against the current shim. The test scenario comes from their report.
Refs: #63535
Refs: #63538
The new test fails on main and passes with this change. ESLint is clean on the changed files, and
tools/test.py -j1passes forparallel/test-fs-glob*andparallel/test-path-glob.AI disclosure: I used a coding agent to help find the bug and draft the test. I reproduced the behavior on main, reviewed the change line by line, and ran the tests above locally.